<?php
namespace plugins\feedback\controller;

use cmf\controller\PluginAdminBaseController;
use think\Db;
use think\Request;

/**
 * 
 */
class ApiIndexController extends PluginAdminBaseController
{

    /**
     * 意见反馈-提交
     */
    public function submit()
    {

        $param = $this->request->post();
        if( empty( $param['type']) || empty($param['content']) || empty($param['mobile']) ){
            return api_json_echo( false , '请传类型、手机号及内容' , '' ,100 );
        }
        
        $data = ['content'=>$param['content'],'mobile'=>$param['mobile']];
        $data['type'] = db('feedback_type')->where('id',$param['type'])->find()['title'];
  
        if( $_FILES )
        {
            $img = [];
            foreach( $_FILES as $key => $value )
            {
                foreach( $value as $ke => $va )
                {
                    foreach( $va as $k => $v )
                    {
                        if( $k > 2 )return api_json_echo(false,'上传的图数超出限制','',101);
                        $img[$k][$ke]=$v;
                    }
                }
            } 
            foreach( $img as $key  => $value)
            { 
                $files= uploadImg( $value, '/upload/feedback');
                if( $files['status'] == true ) $img[$key]=['img'=>$files['data']];
            }
            $data['img'] = json_encode($img);
        }

        $res = db('feedback')->insert($data);
        if($res) return api_json_echo( false , '提交成功' , '' , 200);
        return api_json_echo( true , '提交失败' , '' , 102);
    }



}